home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / SciAn / src / ScianWindowFunctions.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  17KB  |  570 lines

  1. /*ScianWindowFunctions.c
  2.   Eric Pepke
  3.   10 August 1993
  4.  
  5.   Does window functions, i.e., functions that work on individual windows.
  6. */
  7.  
  8. #include "Scian.h"
  9. #include "ScianTypes.h"
  10. #include "ScianLists.h"
  11. #include "ScianWindows.h"
  12. #include "ScianColors.h"
  13. #include "ScianIDs.h"
  14. #include "ScianObjWindows.h"
  15. #include "ScianButtons.h"
  16. #include "ScianErrors.h"
  17. #include "ScianDraw.h"
  18. #include "ScianControls.h"
  19. #include "ScianArrays.h"
  20. #include "ScianScripts.h"
  21. #include "ScianVisWindows.h"
  22. #include "ScianIcons.h"
  23. #include "ScianEvents.h"
  24. #include "ScianStyle.h"
  25. #include "ScianWindowFunctions.h"
  26. #include "ScianHelp.h"
  27. #include "ScianFilters.h"
  28. #include "ScianFileSystem.h"
  29. #include "ScianSockets.h"
  30. #include "ScianPointers.h"
  31. #include "ScianMenus.h"
  32. #include "ScianPreferences.h"
  33. #include "ScianFileSystem.h"
  34. #include "ScianAnimation.h"
  35. #include "ScianSymbols.h"
  36.  
  37. ObjPtr windowActionClass;
  38. ObjPtr toggledWindowActionClass;
  39.  
  40. typedef struct
  41.     {
  42.     char *name;        /*Name of function*/
  43.     NameTyp message;    /*Message to send to window*/
  44.     char *buttonHelp;    /*Button help*/
  45.     char *menuHelp;        /*Menu help*/
  46.     char *scriptLine;    /*Line for script*/
  47.     ObjPtr menu;        /*Which menu this routine is in*/
  48.     int menuGroup;        /*Which menu group this function is in*/
  49.     } WindowFunction;
  50.  
  51. int nWindowFunctions = 0;    /*# of window functions*/
  52.  
  53. static WindowFunction *windowFunctions;
  54.  
  55. #ifdef PROTO
  56. int NameToWindowFunction(char *name)
  57. #else
  58. int NameToWindowFunction(name)
  59. char *name;
  60. #endif
  61. /*Converts a name to a function number, or -1*/
  62. {
  63.     int funcNum;
  64.  
  65.     /*Search for the named function*/
  66.     for (funcNum = 0; funcNum < nWindowFunctions; ++funcNum)
  67.     {
  68.     if (0 == strcmp2(name, windowFunctions[funcNum] . name))
  69.     {
  70.         break;
  71.     }
  72.     }
  73.  
  74.     if (funcNum >= nWindowFunctions)
  75.     {
  76.     /*Not found, too bad.*/
  77.     char nameStr[300];
  78.     sprintf(nameStr, "Internal error: name '%s' not found", name);
  79.     ReportError("NameToWindowFunction", nameStr);
  80.     return -1;
  81.     }
  82.     return funcNum;
  83. }
  84.  
  85. #ifdef PROTO
  86. Bool WindowFunctionScriptLine(char *line)
  87. #else
  88. Bool WindowFunctionScriptLine(line)
  89. char *line;
  90. #endif
  91. /*If s is a script line, finds out if it is a valid script line for a
  92.   window function.  If so, does it and returns true, otherwise does nothing
  93.   and returns false.  Determines whether it is valid by matching the 
  94.   script line*/
  95. {
  96.     int funcNum;
  97.     register char *s, *p, *t;
  98.  
  99.     /*For all possible functions*/
  100.     for (funcNum = 0; funcNum < nWindowFunctions; ++funcNum)
  101.     {
  102.     /*Try to match script line against script*/
  103.     s = line;
  104.     p = windowFunctions[funcNum] . scriptLine;
  105.  
  106.     if (!p) continue;
  107.  
  108.     SKIPBLANKS(s);
  109.     SKIPBLANKS(p);
  110.  
  111.     while (*p)
  112.     {
  113.         if (isspace(*p))
  114.         {
  115.         SKIPBLANKS(s);
  116.         SKIPBLANKS(p);
  117.         }
  118.         else if (toupper(*p) != toupper(*s))
  119.         {
  120.         /*Failure to match*/
  121.         break;
  122.         }
  123.         else
  124.         {
  125.         ++s;
  126.         ++p;
  127.         }
  128.     }
  129.  
  130.     if (*p == 0)
  131.     {
  132.         ObjPtr list;
  133.         ThingListPtr runner;
  134.         ObjPtr object;
  135.         /*It's a match!  Do this function and return true*/
  136.  
  137.         Log(windowFunctions[funcNum] . scriptLine);
  138.         Log("\n");
  139.  
  140.         DeferMessage((ObjPtr) selWinInfo, windowFunctions[funcNum] . message);
  141.  
  142.         return true;
  143.     }
  144.     }
  145.     return false;
  146. }
  147.  
  148. #ifdef PROTO
  149. void DefineWindowFunction(char *funcName, NameTyp message,
  150.     char *scriptLine,
  151.     char *buttonHelp,
  152.     char *menuHelp, ObjPtr menu, int menuGroup)
  153. #else
  154. void DefineWindowFunction(funcName, message, scriptLine,
  155.     buttonHelp, menuHelp, menu, menuGroup)
  156. char *funcName;
  157. NameTyp message;
  158. char *scriptLine;
  159. char *buttonHelp;
  160. char *menuHelp;
  161. ObjPtr menu;
  162. int menuGroup;
  163. #endif
  164. /*Defines a window function
  165.     funcName        is the name of the function for the menu and buttons
  166.     message        is a message to do it
  167.     scriptLine        is the script line
  168.     buttonHelp        is the help string for a button, or nothing for no button
  169.     menuHelp        is the help string for a menu
  170.     menu        is which menu to use, or NULLOBJ for none
  171.     menuGroup        is the menu group
  172. */
  173. {
  174.     if (nWindowFunctions)
  175.     {
  176.     windowFunctions = Realloc(windowFunctions, (nWindowFunctions + 1) * sizeof(WindowFunction));
  177.     }
  178.     else
  179.     {
  180.     windowFunctions = Alloc((nWindowFunctions + 1) * sizeof(WindowFunction));
  181.     }
  182.  
  183.     if (funcName)
  184.     {
  185.     windowFunctions[nWindowFunctions] . name = Alloc(strlen(funcName) + 1);
  186.     strcpy(windowFunctions[nWindowFunctions] . name, funcName);
  187.     }
  188.     else
  189.     {
  190.     windowFunctions[nWindowFunctions] . name = (char *) 0;
  191.     }
  192.     windowFunctions[nWindowFunctions] . message = message;
  193.     windowFunctions[nWindowFunctions] . menu = menu;
  194.     windowFunctions[nWindowFunctions] . menuGroup = menuGroup;
  195.     if (scriptLine)
  196.     {
  197.     windowFunctions[nWindowFunctions] . scriptLine = Alloc(strlen(scriptLine) + 1);
  198.     strcpy(windowFunctions[nWindowFunctions] . scriptLine, scriptLine);
  199.     }
  200.     else
  201.     {
  202.     windowFunctions[nWindowFunctions] . scriptLine = (char *) 0;
  203.     }
  204.     if (buttonHelp)
  205.     {
  206.     windowFunctions[nWindowFunctions] . buttonHelp = Alloc(strlen(buttonHelp) + 1);
  207.     strcpy(windowFunctions[nWindowFunctions] . buttonHelp, buttonHelp);
  208.     }
  209.     else
  210.     {
  211.     windowFunctions[nWindowFunctions] . buttonHelp = (char *) 0;
  212.     }
  213.     if (menuHelp)
  214.     {
  215.     windowFunctions[nWindowFunctions] . menuHelp = Alloc(strlen(menuHelp) + 1);
  216.     strcpy(windowFunctions[nWindowFunctions] . menuHelp, menuHelp);
  217.     }
  218.     else
  219.     {
  220.     windowFunctions[nWindowFunctions] . menuHelp = (char *) 0;
  221.     }
  222.  
  223.     /*Put it on the appropriate menu*/
  224.     if (menu)
  225.     {
  226.     /*Put it on menu*/
  227.     ObjPtr action;
  228.  
  229.     action = NewAction(funcName, windowActionClass);
  230.     SetVar(action, HELPSTRING, NewString(menuHelp));
  231.     AddMenuItem(menu, action, menuGroup);
  232.     }
  233.  
  234.     ++nWindowFunctions;
  235. }
  236.  
  237. #ifdef PROTO
  238. void DefineToggledWindowMenuItem(char *trueName, char *falseName, NameTyp flag, ObjPtr menu, int menuGroup)
  239. #else
  240. void DefineToggledWindowMenuItem(trueName, falseName, flag, menu, menuGroup)
  241. char *trueName;
  242. char *falseName;
  243. NameTyp flag;
  244. ObjPtr menu;
  245. int menuGroup;
  246. #endif
  247. /*Defines a menu item that toggles between window functions trueName and falseName 
  248.  based on flag in group at menu*/
  249. {
  250.     ObjPtr action;
  251.  
  252.     action = NewAction((char *) 0, toggledWindowActionClass);
  253.     SetVar(action, WHICHVAR, NewSymbol(flag));
  254.     SetVar(action, TRUENAME, NewString(trueName));
  255.     SetVar(action, FALSENAME, NewString(falseName));
  256.  
  257.     DeclareDependency(action, NAME, MOUSEWINDOW);
  258.     DeclareIndirectDependency(action, NAME, MOUSEWINDOW, flag);
  259.  
  260.     AddMenuItem(menu, action, menuGroup);
  261. }
  262.  
  263. ObjPtr MakeToggledWindowActionName(action)
  264. ObjPtr action;
  265. /*Makes a toggled window action's name*/
  266. {
  267.     ObjPtr var;
  268.     NameTyp whichVar;
  269.  
  270.     var = GetSymbolVar("MakeToggledWindowActionName", action, WHICHVAR);
  271.     if (!var) return ObjFalse;
  272.     whichVar = GetSymbolID(var);
  273.  
  274.     if (GetPredicate((ObjPtr) selWinInfo, whichVar))
  275.     {
  276.     SetVar(action, NAME, GetVar(action, TRUENAME));
  277.     }
  278.     else
  279.     {
  280.     SetVar(action, NAME, GetVar(action, FALSENAME));
  281.     }
  282.  
  283.     return ObjTrue;
  284. }
  285.  
  286. ObjPtr MakeToggledWindowMenuHelp(action, class)
  287. ObjPtr action;
  288. ObjPtr class;
  289. /*Makes a toggled window action's menu help*/
  290. {
  291.     char help[600], *s;
  292.     ObjPtr var, var2;
  293.     int whichFunction;
  294.  
  295.     MakeVar(action, NAME);
  296.     var = GetStringVar("MakeToggledWindowActionHelp", action, NAME);
  297.     if (!var) return NULLOBJ;
  298.  
  299.     whichFunction = NameToWindowFunction(GetString(var));
  300.  
  301.     strcpy(help, windowFunctions[whichFunction] . menuHelp);
  302.     s = help;
  303.     while (*s) ++s;
  304.     *s = '\0';
  305.  
  306.     var = GetStringVar("MakeToggledWindowActionHelp", action, TRUENAME);
  307.     if (var)
  308.     {
  309.     var2 = GetStringVar("MakeToggledWindowActionHelp", action, FALSENAME);
  310.     if (var2)
  311.     {
  312.         sprintf(s, "\n\nThis menu item toggles between '%s' and '%s' depending on the state of the window.\n",
  313.         GetString(var), GetString(var2));
  314.     }
  315.     }
  316.  
  317.     SetVar(class, HELPSTRING, NewString(help));
  318.  
  319.     return ObjTrue;
  320. }
  321.  
  322. ObjPtr WindowAction(action)
  323. ObjPtr action;
  324. /*Does the action method of a window action*/
  325. {
  326.     int whichFunction;
  327.     ObjPtr var;
  328.  
  329.     var = GetVar(action, NAME);
  330.     if (var)
  331.     {
  332.     whichFunction = NameToWindowFunction(GetString(var));
  333.     if (contextHelp)
  334.     {
  335.         /*Give help on the action*/
  336.         ContextHelp(action);
  337.         contextHelp = false;
  338.         MySetCursor(0);
  339.     }
  340.     else
  341.     {
  342.         /*Log it*/
  343.         if (windowFunctions[whichFunction] . scriptLine)
  344.         {
  345.         Log(windowFunctions[whichFunction] . scriptLine);
  346.         Log("\n");
  347.         }
  348.         /*Do it*/
  349.         if (selWinInfo)
  350.         {
  351.         DeferMessage((ObjPtr) selWinInfo, windowFunctions[whichFunction] . message);
  352.         }
  353.     }
  354.     }
  355.     return ObjTrue;
  356. }
  357.  
  358. ObjPtr ToggledWindowAction(action)
  359. ObjPtr action;
  360. /*Does the action method of a toggled window action*/
  361. {
  362.     int whichFunction;
  363.     ObjPtr var;
  364.     ObjPtr parent;
  365.  
  366.     MakeVar(action, NAME);
  367.     var = GetVar(action, NAME);
  368.     if (var)
  369.     {
  370.     whichFunction = NameToWindowFunction(GetString(var));
  371.     if (contextHelp)
  372.     {
  373.         /*Give help on the action*/
  374.         ContextHelp(action);
  375.         contextHelp = false;
  376.         MySetCursor(0);
  377.     }
  378.     else
  379.     {
  380.         /*Log it*/
  381.         if (windowFunctions[whichFunction] . scriptLine)
  382.         {
  383.         Log(windowFunctions[whichFunction] . scriptLine);
  384.         Log("\n");
  385.         }
  386.         /*Do it*/
  387.         if (selWinInfo)
  388.         {
  389.         DeferMessage((ObjPtr) selWinInfo, windowFunctions[whichFunction] . message);
  390.         }
  391.     }
  392.     }
  393.  
  394.     /*Make everything changed, so that it will have to remake menu*/
  395.     SetVar(action, CHANGED, ObjTrue);
  396.  
  397.     parent = action;
  398.     while (parent = GetVar(parent, PARENT))
  399.     {
  400.     SetVar(parent, ITEMS, GetVar(parent, ITEMS));
  401.     }
  402.  
  403.     return ObjTrue;
  404. }
  405.  
  406. static ObjPtr MakeWindowActionActivated(action)
  407. ObjPtr action;
  408. /*Makes a window action activated*/
  409. {
  410.     ObjPtr allSelected;
  411.     ThingListPtr runner;
  412.     int f;
  413.     ObjPtr var;
  414.  
  415.     MakeVar(action, NAME);
  416.     var = GetStringVar("MakeWindowActionActivated", action, NAME);
  417.     if (!var) return ObjFalse;
  418.     f = NameToWindowFunction(GetString(var));
  419.     if (f < 0) return ObjFalse;
  420.  
  421.     if (selWinInfo)
  422.     {
  423.     if (GetMethod((ObjPtr) selWinInfo, windowFunctions[f] . message))
  424.     {
  425.         SetVar(action, ACTIVATED, ObjTrue);
  426.         return ObjTrue;
  427.     }
  428.     }
  429.     SetVar(action, ACTIVATED, ObjFalse);
  430.     return ObjTrue;
  431. }
  432.  
  433. #ifdef PROTO
  434. void InitWindowFunctions(void)
  435. #else
  436. void InitWindowFunctions()
  437. #endif
  438. /*Initializes the window function system*/
  439. {
  440.     /*Make the class for window actions*/
  441.     windowActionClass = NewObject(actionClass, 0L);
  442.     AddToReferenceList(windowActionClass);
  443.     SetMethod(windowActionClass, ACTIONMETHOD, WindowAction);
  444.     SetVar(windowActionClass, ACTIVATED, ObjFalse);
  445.     SetMethod(windowActionClass, ACTIVATED, MakeWindowActionActivated);
  446.     DeclareDependency(windowActionClass, ACTIVATED, READYTOACTIVATE);
  447.  
  448.     /*Make the class for toggled window actions*/
  449.     toggledWindowActionClass = NewObject(windowActionClass, 0L);
  450.     AddToReferenceList(toggledWindowActionClass);
  451.     SetMethod(toggledWindowActionClass, ACTIONMETHOD, ToggledWindowAction);
  452.     DeclareDependency(toggledWindowActionClass, NAME, CHANGED);
  453.     SetMethod(toggledWindowActionClass, NAME, MakeToggledWindowActionName);
  454.     SetMethod(toggledWindowActionClass, MAKE1HELPSTRING, MakeToggledWindowMenuHelp);
  455.  
  456.     /*Define the actions*/
  457.     DefineWindowFunction(WF_SAVEWINDOW, SAVEWINDOW, "save window",
  458.     "Pressing this button saves the image in the window to a file, using the window saver chosen in the Preferences control panel.",
  459.     "Choosing this menu item saves the image in the window to a file, using the window saver chosen in the Preferences control panel.",
  460.     windowMenu, 1);
  461.  
  462.     DefineWindowFunction(WF_SAVEFWINDOW, SAVEFWINDOW, "save framed window",
  463.     "Pressing this button saves the image in the window including its frame to a file, using the window saver chosen in the Preferences control panel.",
  464.     "Choosing this menu item saves the image in the window including its frame to a file, using the window saver chosen in the Preferences control panel.",
  465.     windowMenu, 1);
  466.  
  467.     DefineWindowFunction(WF_SAVESCREEN, SAVESCREEN, "save screen",
  468.     "Pressing this button saves the image on the screen to a file, using the window saver chosen in the Preferences control panel.",
  469.     "Choosing this menu item saves the image on the screen to a file, using the window saver chosen in the Preferences control panel.",
  470.     windowMenu, 1);
  471.  
  472.     DefineWindowFunction(WF_SHOWPANEL, SHOWPANEL, "show panel",
  473.     "Pressing this button shows the control panels of a visualization window.",
  474.     "Choosing this menu item shows the control panels of a visualization window.",
  475.     NULLOBJ, 1);
  476.  
  477.     DefineWindowFunction(WF_HIDEPANEL, HIDEPANEL, "hide panel",
  478.     "Pressing this button hides the control panels of a visualization window.",
  479.     "Choosing this menu item hides the control panels of a visualization window.",
  480.     NULLOBJ, 1);
  481.  
  482.     DefineToggledWindowMenuItem(WF_SHOWPANEL, WF_HIDEPANEL, PANELHIDDEN, windowMenu, 1);
  483.  
  484.     DefineWindowFunction(WF_PREVSCREEN, PREVSCREEN, (char *) 0,
  485.     "Pressing this button undoes the last change in window size and location.",
  486.     "Choosing this menu item undoes the last change in window size and location.",
  487.     locationMenu, 1);
  488.  
  489.     DefineWindowFunction(WF_FULLSCREEN, FULLSCREEN, (char *) 0,
  490.     "Pressing this button expands the window to cover the full screen.",
  491.     "Choosing this menu item expands the window to cover the full screen.",
  492.     locationMenu, 1);
  493.  
  494.     DefineWindowFunction(WF_VIDEOSCREEN, VIDEOSCREEN, (char *) 0,
  495.     "Pressing this button resizes and moves the window to cover the video screen at the lower left corner \
  496. of the workstation screen.  This is useful for doing animations in Silicon Graphics 'NTSC' mode.",
  497.     "Choosing this menu item resizes and moves the window to cover the video screen at the lower left corner \
  498. of the workstation screen.  This is useful for doing animations in Silicon Graphics 'NTSC' mode.",
  499.     locationMenu, 1);
  500.  
  501.     DefineWindowFunction(WF_DOUBLEVID, DOUBLEVIDSCREEN, (char *) 0,
  502.     "Pressing this button resizes and moves the window to cover an area twice the size of the video screen at the lower left corner \
  503. of the workstation screen.  This is useful for doing animations in Silicon Graphics 'NTSC' mode when the 4 to 1 reduction filter is on \
  504. in the Renderer control panel.",
  505.     "Choosing this menu item resizes and moves the window to cover an area twice the size of the video screen at the lower left corner \
  506. of the workstation screen.  This is useful for doing animations in Silicon Graphics 'NTSC' mode when the 4 to 1 reduction filter is on \
  507. in the Renderer control panel.",
  508.     locationMenu, 1);
  509.  
  510.     DefineWindowFunction(WF_PHSCSCREEN, PHSCSCREEN, (char *) 0,
  511.     "Pressing this button resizes and moves the window to cover an area at the lower left corner \
  512. the right size and shape for saving images for a PHSCologram.  The image will appear on its side, skewed \
  513. to compensate for the aspect ratio of the PHSCologram.  PHSColograms are barrier strip \
  514. autostereograms produced by Ellen Sandor and Stephan Myers at the Art(n) Institute.",
  515.     "Choosing this menu item resizes and moves the window to cover an area at the lower left corner \
  516. the right size and shape for saving images for a PHSCologram.  The image will appear on its side, skewed \
  517. to compensate for the aspect ratio of the PHSCologram.  PHSColograms are barrier strip \
  518. autostereograms produced by Ellen Sandor and Stephan Myers at the Art(n) Institute.",
  519.     locationMenu, 1);
  520.  
  521.    DefineWindowFunction(WF_SHOWFPCONTROLS, SHOWFPCONTROLS, "show front panel controls",
  522.     "Pressing this button shows the controls for the 2-D panel in front of the space in this window.",
  523.     "Choosing this menu item shows the controls for the 2-D panel in front of the space in this window.",
  524.     windowMenu, 2);
  525.  
  526.    DefineWindowFunction(WF_SHOWBPCONTROLS, SHOWBPCONTROLS, "show back panel controls",
  527.     "Pressing this button shows the controls for the 2-D panel in back of the space in this window.",
  528.     "Choosing this menu item shows the controls for the 2-D panel in back of the space in this window.",
  529.     windowMenu, 2);
  530.  
  531.    DefineWindowFunction(WF_SHOWSPCONTROLS, SHOWSPCONTROLS, "show space controls",
  532.     "Pressing this button shows the controls for the space in this window.",
  533.     "Choosing this menu item shows the controls for the space in this window.",
  534.     windowMenu, 2);
  535.  
  536.     DefineWindowFunction(WF_TILEFULL, TILEFULL, (char *) 0,
  537.     "Pressing this button tiles all the visualization windows to cover the full screen.",
  538.     "Choosing this menu item tiles all the visualization windows to cover the full screen.",
  539.     tileMenu, 1);
  540.  
  541.     DefineWindowFunction(WF_TILEVIDEO, TILEVIDEO, (char *) 0,
  542.     "Pressing this button tiles all the visualization windows to cover the video screen at the lower left corner \
  543. of the workstation screen.  This is useful for doing animations in Silicon Graphics 'NTSC' mode.",
  544.     "Choosing this menu item tiles all the visualization windows to cover the video screen at the lower left corner \
  545. of the workstation screen.  This is useful for doing animations in Silicon Graphics 'NTSC' mode.",
  546.     tileMenu, 1);
  547. }
  548.  
  549. #ifdef PROTO
  550. void KillWindowFunctions(void)
  551. #else
  552. void KillWindowFunctions()
  553. #endif
  554. /*Kills the window function system*/
  555. {
  556.     int k;
  557.  
  558.     for (k = 0; k < nWindowFunctions; ++k)
  559.     {
  560.     SAFEFREE(windowFunctions[k] . name);
  561.     SAFEFREE(windowFunctions[k] . scriptLine);
  562.     SAFEFREE(windowFunctions[k] . menuHelp);
  563.     SAFEFREE(windowFunctions[k] . buttonHelp);
  564.     }
  565.     SAFEFREE(windowFunctions);
  566.     RemoveFromReferenceList(windowActionClass);
  567.     RemoveFromReferenceList(toggledWindowActionClass);
  568. }
  569.  
  570.